<template>
  <div>
    <el-dialog
      class="dialog_account"
      title="新增账户"
      :visible.sync="dialogVisible"
      lock-scroll
      width="800px"
    >
      <div class="dialog_div_new">
        <div class="dialog_middle">
          <div class="input_line">
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">账户名称</div>
                <span class="star">*</span>
              </div>
              <input
                type="text"
                ref="nameRef"
                @focusout="getNameToPinying"
                v-model="ruleForm.bankName"
              />
            </div>
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">账户类别</div>
                <span class="star">*</span>
              </div>
              <el-select v-model="ruleForm.bankType">
                <el-option
                  v-for="item in zhlbOptions"
                  :key="item.id"
                  :label="item.typeName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </div>
          </div>
          <div class="input_line">
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">开户银行</div>
              </div>
              <input type="text" v-model="ruleForm.openBank" />
            </div>
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">开户名</div>
              </div>
              <input type="text" v-model="ruleForm.openMan" />
            </div>
          </div>

          <div class="input_line">
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">账号</div>
              </div>
              <input type="text" v-model="ruleForm.account" />
            </div>
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">币种</div>
              </div>
              <j-dict-select-tag
                type="select"
                dictCode="currency_type"
                style="flex: 1"
                v-model="ruleForm.moneyType"
                placeholder="请选择币种符号"
              ></j-dict-select-tag>
            </div>
          </div>

          <div class="input_line">
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">拼音码</div>
              </div>
              <input type="text" v-model="ruleForm.helpCode" />
            </div>
            <div class="line_item">
              <div style="width: 80px; display: flex">
                <div class="title">默认账户</div>
              </div>
              <el-checkbox v-model="ruleForm.defaultFlag"></el-checkbox>
            </div>
          </div>
        </div>
        <div class="dialog_bottom">
          <el-button type="primary" @click.stop="onSubmit">保存</el-button>
          <el-button @click.stop="dialogVisible = false">取消</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getAction, deleteAction, postAction, putAction, downPostFile } from '@/api/manage'
import { handlePermissions, handleOtherPerms, getTreeDataByMap, getLikeCompanyId } from '@/utils/index'

export default {
  created () { },
  data () {
    return {
      ruleForm: {
        bankName: '',
        bankType: '',
        openBank: '',
        openMan: '',
        account: '',
        moneyType: '',
        helpCode: '',
        defaultFlag: false,
      },
      zhlbOptions: [],
      dialogVisible: false,
    }
  },
  methods: {
    show () {
      this.ruleForm = this.$options.data().ruleForm
      this.getTreeData()
      this.dialogVisible = true
    },
    // 转换拼音码
    getNameToPinying (event) {
      this.ruleForm.helpCode = this.$pinyin.getJp(event.target.value)
    },
    // 获取类别数据
    getTreeData () {
      getAction('/xghbanktype/xghBankType/list', {}).then((res) => {
        if (res.code === 200) {
          let list = res.result
          this.zhlbOptions = list
        } else {
          this.$elMessage({
            message: res.message,
            type: 'error',
          })
        }
      })
    },
    async onSubmit () {
      if (!this.ruleForm.bankName || !this.ruleForm.bankType) {
        return this.$elMessage({
          message: '名称或者类别不能为空！',
          type: 'warning',
        })
      }
      // 默认账户、、0-非默认 1-默认
      let params = {
        ...this.ruleForm,
        defaultFlag: this.ruleForm.defaultFlag ? 1 : 0
      }
      const res = await postAction('/xghBank/xghBank/add', params)
      if (res.code !== 200) {
        return this.$elMessage.error(res.message)
      }
      this.dialogVisible = false
      this.$emit('onAddSubmit', true)
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  .el-dialog__body {
    padding: 0;
  }
  .el-dialog__header {
    width: 100%;
    height: 0.937559rem;
    box-sizing: border-box;
    padding: 0 0.375023rem;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    justify-content: space-between;
    span {
      font-size: 0.300019rem;
      color: #666;
      font-weight: 600;
    }
    .el-dialog__headerbtn {
      position: static;
      .el-icon-close {
        color: #999;
        font-size: 0.48753rem;
      }
    }
  }
}
.dialog_div_new {
  width: 100%;
  overflow: auto;
  background: #fff;

  .dialog_middle {
    margin-top: 30px;
    padding-bottom: 0;
    box-sizing: border-box;
    padding: 0 0.375023rem;
    overflow: auto;

    div {
      input {
        flex: 1;
        height: 30px;
        background: #ffffff;
        border: 1px solid #e3e3e3;
        border-radius: 0.075005rem;
        font-size: 12px;
        color: #666;
        box-sizing: border-box;
        padding: 0 8px;

        &:focus {
          outline: none;
          border-color: #1890ff;
        }
      }

      ::v-deep .el-select {
        flex: 1;

        .el-input {
          .el-input__inner {
            height: 30px;
            background: #ffffff;
            border: 1px solid #e3e3e3;
            border-radius: 0.075005rem;
            font-size: 12px;
            color: #666;
            box-sizing: border-box;
            padding: 0 8px;
          }

          .el-input__suffix {
            height: 30px;
            display: flex;
            align-items: center;
          }
        }
      }

      ::v-deep .el-checkbox {
        flex: 1;
      }
    }

    .input_line {
      display: flex;
      height: 50px;
      // margin: 5px;

      .line_item {
        width: 50%;
        display: flex;
        padding: 5px 20px;
        align-items: center;

        .title {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 17px;
          color: #666666;
          width: auto;
          min-width: 50px;
          text-align: justify;
          text-justify: distribute-all-lines;
          /*ie6-8*/
          text-align-last: justify;
          /* ie9*/
          -moz-text-align-last: justify;
          /*ff*/
          -webkit-text-align-last: justify;
          /*chrome 20+*/
        }

        .star {
          color: #ff0000;
          margin-left: 10px;
        }
      }
    }
  }

  .dialog_bottom {
    width: 100%;
    height: 100px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;

    ::v-deep .el-button {
      width: 60px;
      height: 30px;
      text-align: center;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      border-radius: 0.1rem;
      background: #fff;
      border: 1px solid #dddddd;
      color: #666666;
    }

    ::v-deep .el-button--primary {
      background: #1890ff;
      border-color: #1890ff;
      color: #fff;
      margin-right: 0.112507rem;
    }

    ::v-deep .el-button--default {
      margin-left: 0.112507rem;
    }
  }
}

.disabled_button {
  background: #cbced3 !important;
  color: #666 !important;
}
</style>